const app = getApp()
const api = wx.getStorageSync('api')
let user
Page({
  data: {
    address: null,
    price: parseInt('64950'),
    steps: [{
        text: '买家下单',
      },
      {
        text: '双方议价',
      },
      {
        text: '买家提货',
      },
      {
        text: '交易完成',
        activeIcon: 'success',
      },
    ],
    stepActive: '3',
    activeNames: ['0'],
    id: '', // 商品id
    order: null // 商品详情
  },

  getOrderById(id) {
    const url = api.order_detail + `?orderId=${id}`
    app.$http.get(url).then(res => {
      console.log(res)
      this.setData({
        order: res.data.order,
        address: res.data.address,
        id
      })
    })
  },

  onLoad: function (options) {
    user = wx.getStorageSync('user')
    // const id = 'f6a6b8cb4a2241baa0ce209f4fea7ed5'
    const id = options.id
    this.getOrderById(id)
  },

  onChange(event) {
    this.setData({
      activeNames: event.detail,
    });
  },

  showConfirm() {
    wx.showModal({
      title: '提示',
      content: '如不满意价格，请与客服沟通；如满意，请点击同意价格',
      confirmText: '确认',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  /**
   * 议价提示
   */
  showConfirm2(e) {
    let order = this.data.order
    wx.showModal({
      title: '提示',
      content: '如不满意价格，请与客服沟通；如同意，将到发货阶段',
      confirmText: '同意价格',
      success: (res) => {
        if (res.confirm) {
          wx.request({
            url: serverUrl + '/zOrderForm/update',
            method: 'POST',
            data: {
              statusId: 2,
              id: order.id,
              version: order.version
            },
            success: res => {
              console.log(res)
              wx.showToast({
                title: res.data.message,
                icon: 'none'
              })
              this.getOrderById(this.data.id)
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  }
})